/****************************************************************
 * <strong>MFDataEdit</strong>
 *
 * <p>
 *MFDataEdit虚拟化Edit 
 * </p>
 *
 * @author AndyZhang 2011 cnet2001@163.com
 * @version 0.1
 * ToDo:2011-11-29 
 ***************************************************************/

package com.thinkwide.data.vdata;

public class MFDataEdit {
    private String field;
    private int index;
    private boolean visible;
    private boolean enable;
    private int resCode;
    private String onclick = "";
    private String htmlAttribute = "";
    private String title = "";
    private String width;
    private String editWidth = "120px";
    private String template;
    private String lableformat;
    private String tag;
    private String dataType;
    private MFDataEditFieldType xdataType = MFDataEditFieldType.dftString;
    private String dateFormat;
    private String defaultValue = "";
    private Object data;
    private int length;
    private boolean allowNull;
    private MFDataEdits parent;
    private boolean primaryKey;
    private boolean indexKey;
    private String lookupid;
    private String format;
    private boolean allowSort;
    private MFDataEditViewType viewType;

    public MFDataEdit() {
        primaryKey = false;
        indexKey = false;
        visible = true;
        enable = true;
        allowNull = true;
        allowSort = true;
        viewType = MFDataEditViewType.input;
    }

    public MFDataEdit(String field) {
        this();
        this.field = field;
    }

    public MFDataEdit(String field, String title, String width, MFDataEditViewType viewType) {
        this(field);
        this.field = field;
        this.title = title;
        this.width = width;
        this.viewType = viewType;
        switch (viewType) {
            case input:
                this.setXdataType(MFDataEditFieldType.dftString);
                break;
            case lookup:
                this.setXdataType(MFDataEditFieldType.dftString);
                break;
            case datePicker:
                this.setXdataType(MFDataEditFieldType.dftDate);
                break;
            case datePickerExt:
                this.setXdataType(MFDataEditFieldType.dftDate2);
                break;
            case number:
                this.setXdataType(MFDataEditFieldType.dftInt);
                break;
            case lable:
                this.setXdataType(MFDataEditFieldType.dftNone);
                break;
        }
    }

    public MFDataEdit(String field, String title, String width, String lookupid) {
        this(field);
        this.field = field;
        this.title = title;
        this.width = width;
        this.viewType = MFDataEditViewType.lookup;
        this.xdataType = MFDataEditFieldType.dftString;
        this.lookupid = lookupid;
    }

    public MFDataEdit(String field, String title, MFDataEditViewType viewType) {
        this(field);
        this.field = field;
        this.title = title;
        this.viewType = viewType;
        this.xdataType = MFDataEditFieldType.dftString;
    }

    public MFDataEdit(String field, String title, String lookupid) {
        this(field);
        this.field = field;
        this.title = title;
        this.viewType = MFDataEditViewType.lookup;
        this.lookupid = lookupid;
        this.xdataType = MFDataEditFieldType.dftString;
    }

    public MFDataEdit(MFDataEditViewType viewType, String title, String width, String format) {
        this();
        this.title = title;
        this.width = width;
        this.viewType = viewType;
        this.format = format;
    }

    public static MFDataEdit clone(MFDataEdit edit) {
        MFDataEdit newEdit = new MFDataEdit();
        newEdit.setAllowNull(edit.isAllowNull());
        newEdit.setData(edit.getData());
        newEdit.setDataType(edit.getDataType());
        newEdit.setEnable(edit.getEnable());
        newEdit.setField(edit.getField());
        newEdit.setFormat(edit.getFormat());
        newEdit.setLableformat(edit.getLableformat());
        newEdit.setIndex(edit.getIndex());
        newEdit.setLength(edit.getLength());
        newEdit.setLookupid(edit.getLookupid());
        newEdit.setPrimaryKey(edit.isPrimaryKey());
        newEdit.setResCode(edit.getResCode());
        newEdit.setTag(edit.getTag());
        newEdit.setTemplate(edit.getTemplate());
        newEdit.setTitle(edit.getTitle());
        newEdit.setTemplate(edit.getTemplate());
        newEdit.setViewType(edit.getViewType());
        newEdit.setVisible(edit.getVisible());
        newEdit.setWidth(edit.getWidth());

        return newEdit;
    }

    public void setField(String field) {
        this.field = field;
    }

    public String getField() {
        return field;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getTitle() {
        return title;
    }

    public void setDataType(String dataType) {
        this.dataType = dataType;
    }

    public String getDataType() {
        return dataType;
    }

    public void setLength(int length) {
        this.length = length;
    }

    public int getLength() {
        return length;
    }

    public void setAllowNull(boolean allowNull) {
        this.allowNull = allowNull;
    }

    public boolean isAllowNull() {
        return allowNull;
    }

    public void setWidth(String width) {
        this.width = width;
    }

    public String getWidth() {
        return width;
    }

    public void setTemplate(String template) {
        this.template = template;
    }

    public String getTemplate() {
        return template;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public int getIndex() {
        if (parent != null) parent.indexOf(this);
        return index;
    }

    public void setParent(MFDataEdits parent) {
        this.parent = parent;
    }

    public MFDataEdits getParent() {
        return parent;
    }

    public void setResCode(int resCode) {
        this.resCode = resCode;
    }

    public int getResCode() {
        return resCode;
    }

    public void setEnable(boolean enable) {
        this.enable = enable;
    }

    public boolean getEnable() {
        return enable;
    }

    public void setVisible(boolean visible) {
        this.visible = visible;
    }

    public boolean getVisible() {
        return visible;
    }

    public void setPrimaryKey(boolean primaryKey) {
        this.primaryKey = primaryKey;
    }

    public boolean isPrimaryKey() {
        return primaryKey;
    }

    public void setIndexKey(boolean indexKey) {
        this.indexKey = indexKey;
    }

    public boolean isIndexKey() {
        return indexKey;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public Object getData() {
        return data;
    }

    public void setTag(String tag) {
        this.tag = tag;
    }

    public String getTag() {
        return tag;
    }

    public void setFormat(String format) {
        this.format = format;
    }

    public String getFormat() {
        return format;
    }

    public void setViewType(MFDataEditViewType viewType) {
        this.viewType = viewType;
    }

    public MFDataEditViewType getViewType() {
        return viewType;
    }

    public void setLableformat(String lableformat) {
        this.lableformat = lableformat;
    }

    public String getLableformat() {
        return lableformat;
    }

    public void setLookupid(String lookupid) {
        this.lookupid = lookupid;
    }

    public String getLookupid() {
        return lookupid;
    }

    public void setAllowSort(boolean allowSort) {
        this.allowSort = allowSort;
    }

    public boolean isAllowSort() {
        return allowSort;
    }

    public void setDefaultValue(String defaultValue) {
        this.defaultValue = defaultValue;
    }

    public String getDefaultValue() {
        return defaultValue;
    }

    public void setDateFormat(String dateFormat) {
        this.dateFormat = dateFormat;
    }

    public String getDateFormat() {
        return dateFormat;
    }

    public void setXdataType(MFDataEditFieldType xdataType) {
        this.xdataType = xdataType;
    }

    public MFDataEditFieldType getXdataType() {
        return xdataType;
    }

    public void setEditWidth(String editWidth) {
        this.editWidth = editWidth;
    }

    public String getEditWidth() {
        return editWidth;
    }

    public void setHtmlAttribute(String htmlAttribute) {
        this.htmlAttribute = htmlAttribute;
    }

    public String getHtmlAttribute() {
        return htmlAttribute;
    }

    public void setOnclick(String onclick) {
        this.onclick = onclick;
    }

    public String getOnclick() {
        return onclick;
    }
}
